﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.Objects;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Project_mfa.entities;
using System.Configuration;
using System.Diagnostics;

namespace Project_mfa
{
    public partial class Index : System.Web.UI.Page
    {
        private static Logging log = new Logging();

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void hdnFestValue_ValueChanged(object sender, EventArgs e)
        {
            int selected = Convert.ToInt32(((HiddenField)sender).Value);
            Response.Redirect("Festival.aspx?id=" + selected);
        }

        protected void hdnBandValue_ValueChanged(object sender, EventArgs e)
        {

            int selected = Convert.ToInt32(((HiddenField)sender).Value);
            Response.Redirect("Band.aspx?id=" + selected);

        }

        /// <summary>
        /// festival autocomplete methode
        /// get's its data via the entity framework
        /// </summary>
        /// <param name="prefixText">User typed search query</param>
        /// <param name="count"></param>
        /// <param name="contextKey"></param>
        /// <returns></returns>
        [System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
        public static string[] compFest(string prefixText, int count, string contextKey)
        {

            Data db = new Data();

            List<String> names = new List<String>();

            try
            {
                foreach (getFestivalSearch_Result item in db.eGetFestivalNames(prefixText))
                    names.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(item.fest_naam, item.fest_id.ToString()));
            }
            catch (Exception e)
            {
                log.WriteLine("Default", e.Message + " (Searched: " + prefixText + ")");
            }

            return names.ToArray();


        }

        /// <summary>
        /// band autocomplete methode
        /// get's its data via the entity framework
        /// </summary>
        /// <param name="prefixText">User typed search query</param>
        /// <param name="count"></param>
        /// <param name="contextKey"></param>
        /// <returns></returns>
        [System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
        public static string[] compBand(string prefixText, int count, string contextKey)
        {
            Data db = new Data();

            List<String> names = new List<String>();
            try
            {
                foreach (getBandSearch_Result item in db.eGetBandNames(prefixText))
                    names.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(item.band_naam, item.band_id.ToString()));
            }
            catch (Exception e)
            { 
                log.WriteLine("Default", e.Message +" (Searched: " + prefixText +")");
            }

            return names.ToArray();
        }
    }
}